<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>simImportMesh</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../../index.html" TARGET="_top"><img src="../images/homeImg.png"></a></p>

<h1>Regular API function</h1>
<h3 class=subsectionBar><a name="simImportMesh" id="simImportMesh"></a>simImportMesh / sim.importMesh </h3>
<table class=apiTable>
<tr class=apiTableTr> 
<td class=apiTableLeftDescr>
Description 
</td> 
<td class=apiTableRightDescr>Imports a mesh from a file. See also <a href="simExportMesh.htm">sim.exportMesh</a>, <a href="simImportShape.htm">sim.importShape</a> and <a href="simCreateMeshShape.htm">sim.createMeshShape</a><br></td>
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCSyn>
C synopsis
</td> 
<td class=apiTableRightCSyn>simInt simImportMesh(simInt fileformat,const simChar* pathAndFilename,simInt options,simFloat identicalVerticeTolerance,simFloat scalingFactor,simFloat*** vertices,simInt** verticesSizes,simInt*** indices,simInt** indicesSizes,simFloat*** reserved,simChar*** names)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCParam>C parameters</td> 
<td class=apiTableRightCParam>
<div><strong>fileformat</strong>: set to 0. Fileformat is automatically detected</div>

<div><strong>pathAndFilename</strong>: the location of the file to import.<br>
</div>
<div><strong>options</strong>: bit-coded: bit0 set (1): keep identical vertices, bit7 set (128): ignore up-vector coded in fileformat</div>

<div><strong>identicalVerticeTolerance</strong>: has no effect. set to zero<br>
</div>
<div><strong>scalingFactor</strong>: the scaling factor to apply to the imported vertices<br>
</div>
<div><strong>vertices</strong>: an array to vertice arrays. The import operation may generate several meshes depending on the fileformat. The user is in charge of releasing the memory. See the example below<br>
</div>
<div><strong>verticesSizes</strong>: an array indicating the individual vertice array sizes. The user is in charge of releasing the memory. See the example below<br>
</div>
<div><strong>indices</strong>: an array to indice arrays. The import operation may generate several meshes depending on the fileformat. The user is in charge of releasing the memory. Can be nullptr. See the example below<br>
</div>
<div><strong>indicesSizes</strong>: an array indicating the individual indice array sizes. The user is in charge of releasing the memory. Can be nullptr if indices is also nullptr. See the example below<br>
</div>
<div><strong>reserved</strong>: reserved for future extensions. Keep at nullptr.<br>
</div>
<div><strong>names</strong>: not used anymore. Set to nullptr<br>
</div>
<br>
<div>USAGE EXAMPLE:</div>
<pre class=lightBlueBoxNoMarginAndSmall>
simFloat** vertices;
simInt* verticesSizes;
simInt** indices;
simInt* indicesSizes;
simInt elementCount=simImportMesh(1,"d:\\example.dxf",0,0.0001f,1.0f,&vertices,
                            &verticesSizes,&indices,&indicesSizes,nullptr,nullptr);
if (elementCount>0)
{
    const float grey[3]={0.5f,0.5f,0.5f};
    for (int i=0;i&#60;elementCount;i++)
    {
        simInt shapeHandle=simCreateMeshShape(2,20.0f*3.1415f/180.0f,vertices[i],
                               verticesSizes[i],indices[i],indicesSizes[i],nullptr);
        simSetShapeColor(shapeHandle,"",sim_colorcomponent_ambient,grey);
        simReleaseBuffer((simChar*)indices[i]);
        simReleaseBuffer((simChar*)vertices[i]);
    }
    simReleaseBuffer((simChar*)indicesSizes);
    simReleaseBuffer((simChar*)indices);
    simReleaseBuffer((simChar*)verticesSizes);
    simReleaseBuffer((simChar*)vertices);
}</pre>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCRet>
C return value
</td> 
<td class=apiTableRightCRet>
<div>Number of imported meshes, or 0 or -1 if the operation was not successful<br>
</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLSyn>
Lua synopsis
</td> 
<td class=apiTableRightLSyn>table[] vertices,table[] indices=sim.importMesh(int fileformat,string pathAndFilename,int options,float identicalVerticeTolerance,float scalingFactor)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLParam>Lua parameters</td> 
<td class=apiTableRightLParam>
<div>Similar to the C-function counterpart</div>
<div></div></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLRet>
Lua return values
</td> 
<td class=apiTableRightLRet>
<div><strong>vertices</strong>: a table to vertice tables. The import operation may generate several meshes depending on the fileformat. See the example below<br>
</div>
<div><strong>indices</strong>: a table to indice tables. The import operation may generate several meshes depending on the fileformat. See the example below<br>
</div>
<br>
<div>USAGE EXAMPLE (e.g. in a <a href="../customizationScripts.htm">customization script</a>):</div>
<pre class=lightRedBoxNoMarginAndSmall>
if (importButtonPressed) then
    vertices,indices,reserved,names=sim.importMesh(1,"d:\\example.dxf",0,0.0001,1)
    for i=1,#vertices,1 do
        h=sim.createMeshShape(2,20*math.pi/180,vertices[i],indices[i])
        sim.setShapeColor(h,"",sim.colorcomponent_ambient,{0.5,0.5,0.5})
        sim.setObjectAlias(h,names[i])
    end
end</pre>
</td> 
</tr> 
</table> 


<br>
</td>
</tr>
</table>
</div>
</body>
</html>
